home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000207_icon-group-sender _Mon Oct 4 12:38:36 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA09976
  4.     for icon-group-addresses; Mon, 4 Oct 1999 12:38:02 -0700 (MST)
  5. Message-Id: <199910041938.MAA09976@baskerville.CS.Arizona.EDU>
  6. From: eka@corp.cirrus.com (Eka Laiman)
  7. Subject: Re: A small puzzle
  8. To: sbw@tapestry.tucson.az.us (Steve Wampler)
  9. Date: Mon, 4 Oct 1999 10:49:38 -0700 (PDT)
  10. Cc: icon-group@optima.CS.Arizona.EDU
  11. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  12. Status: RO
  13.  
  14. > I haven't posted anything for a while, but thought this might be fun:
  15. >    Write an Icon program to generate the pairings in a round-robin
  16. >    tournament.  The program should accept the player names as
  17. >    command line arguments (see the example below).
  18. > In a round-robin tournament, every player plays every other player
  19. > exactly once.  If there are an odd number of players, then a
  20. > special "bye" player is added.
  21. > ................. edited ..................
  22.  
  23. If I understand the problem correctly, here is how I approach the
  24. problem:
  25.  
  26. Model the problem as "graph" in the following sense:
  27.  
  28.     Each player forms a vertex of the graph. Each pair of player
  29.     is an edge in the graph.
  30.  
  31. >From the condition that every player plays every other player exactly
  32. once, we see the following graph property: each vertex is connected
  33. to every vertex in the graph, forming a "complete graph".
  34.  
  35. Let N be the number of the vertices in the graph, clearly there are
  36.     N(N-1)/2
  37. edges.
  38.  
  39. >From this analysis we come up with the following algorithm:
  40.  
  41.     Let player[1..n] be the array of the players.
  42.  
  43.     1.  Set up the second array partner[1..n] such that:
  44.         partner[i] := player[n - i + 1]
  45.         # initialize partner as the reverse of player.
  46.     2.  Repeat the following steps (n - 1) times:
  47.         2a. For i := 1 to n/2 do
  48.         write(pair(player[i], partner[i])
  49.     2b. Rotate array partner one step.
  50.  
  51. >From the rule of counting, we see that step 2 generates all edges
  52. in our complete graph.
  53.  
  54. I think the implementation of the above algorithm is straightforward.
  55.  
  56. -eka-
  57.